package org.karelun.gef.commands;

import org.eclipse.draw2d.geometry.Point;
import org.karelun.gef.model.ActorModel;
import org.karelun.gef.model.ClassModel;
import org.karelun.gef.model.DiagramModel;
import org.karelun.gef.model.ImageModel;
import org.karelun.gef.model.InterfaceModel;
import org.karelun.gef.model.Node;
import org.karelun.gef.model.PackageModel;
import org.karelun.gef.model.RelationModel;
import org.karelun.gef.model.StateChoiceModel;
import org.karelun.gef.model.StateEndModel;
import org.karelun.gef.model.StateModel;
import org.karelun.gef.model.StateStartModel;
import org.karelun.gef.model.UserCaseModel;

public class CreateNodeCommand extends AbstractCommand {

	private DiagramModel diagram;

	private Node node;

	private Point location;

	public void setModel(Object model) {
		if (model instanceof ClassModel)
			this.node = (ClassModel) model;
		else if(model instanceof PackageModel)
			node=(PackageModel)model;
		else if(model instanceof InterfaceModel)
			node=(InterfaceModel)model;
		else if(model instanceof RelationModel)
			node=(RelationModel)model;
		else if(model instanceof ImageModel)
			node=(ImageModel)model;
		
		else if (model instanceof UserCaseModel)
			this.node = (UserCaseModel) model;
		else if (model instanceof ActorModel)
			this.node = (ActorModel) model;

		else if (model instanceof StateModel)
			this.node = (StateModel) model;
		else if (model instanceof StateStartModel)
			this.node = (StateStartModel) model;
		else if (model instanceof StateEndModel)
			this.node = (StateEndModel) model;
		else if (model instanceof StateChoiceModel)
			this.node = (StateChoiceModel) model;
	}

	public void setDiagram(DiagramModel diagram) {
		this.diagram = diagram;
	}

	public void setLocation(Point location) {
		this.location = location;
	}

	public void execute() {
		if (this.location != null) {
			this.node.setLocation(this.location);
		}
		diagram.addNode(node);
		node.setDiagram(diagram);
	}

	public void redo() {
		execute();
	}

	public void undo() {
		diagram.removeNode(node);
	}
}